#!/bin/bash

RUNDIR="`dirname $0`"
cd $RUNDIR
RUNDIR=`pwd`

jar_name="disease-api-service"
mainconfigDir=/opt/soft/disease-api-service


jar_stop(){
    stat=`ps -ef |grep -w ${jar_name}|grep -v grep |awk '{print $2}'`
    if [[  -z ${stat} ]];then
       echo "[WARN] ${jar_name} server is not running"
    else
       for i in $stat;do
           kill -9 ${i}
       done
       echo "[INFO] stop ${jar_name} server"
    fi
}


jar_start(){
    source /etc/profile >/dev/null 2>&1
    stat=`ps -ef |grep -w ${jar_name}|grep -v grep |awk '{print $2}'`
    if [[  -z ${stat} ]];then
       echo "[INFO] ready to start ${jar_name} server ......"
       cd ${RUNDIR} && nohup java  -Xms1024m -Xmx2048m -XX:MetaspaceSize=1024m -XX:MaxMetaspaceSize=1024m -Xss512k -Xloggc:${RUNDIR}/logs/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=dump.hprof -XshowSettings:vm -Xbootclasspath/a:${mainconfigDir}:${RUNDIR}/config -Dsun.java.command="disease-api-service" -jar ${jar_name}*.jar > /dev/null 2>&1 &
    else
       echo "[WARN] ${jar_name} server is running"
    fi
}



case $1 in
  start)
     jar_start
;;
  stop)
     jar_stop
;;
  restart)
     jar_stop
     jar_start
;;

  *)
   echo "eg: start_server.sh start|stop|restart"
   exit 1
;;
esac
